/*
*********************************************************************************************************
*
*    模块名称 : NTC驱动模块
*    文件名称 : bsp_ntc.c
*    版    本 : V1.1
*    说    明 : 
*
*    修改记录 :
*        版本号    日期           作者          说明
*       V1.0    2017-09-20        armfly          首发
*        V1.1    2019-09-20        armfly          根据参数选择热敏电阻类型。NTC表简化为2列.
*    Copyright (C), 2016-2020, 安富莱电子 www.armfly.com
*
*********************************************************************************************************
*/
#include "bsp.h"
#include "param.h"

/* 温度(摄氏度)，电阻(kΩ)，10K B25/50-3950K */
const float ntc_10K_B3950[] = {
        -55, 739.5,
        -54, 705.664,
        -53, 669.165,
        -52, 631.466,
        -51, 593.686,
        -50, 556.644,
        -49, 520.911,
        -48, 486.858,
        -47, 454.704,
        -46, 424.553,
        -45, 396.426,
        -44, 370.283,
        -43, 346.049,
        -42, 323.623,
        -41, 302.89,
        -40, 283.73,
        -39, 266.022,
        -38, 249.649,
        -37, 234.498,
        -36, 220.466,
        -35, 207.454,
        -34, 195.372,
        -33, 184.139,
        -32, 173.681,
        -31, 163.931,
        -30, 154.827,
        -29, 146.315,
        -28, 138.347,
        -27, 130.877,
        -26, 123.866,
        -25, 117.28,
        -24, 111.084,
        -23, 105.252,
        -22, 99.756,
        -21, 94.573,
        -20, 89.682,
        -19, 85.063,
        -18, 80.699,
        -17, 76.574,
        -16, 72.672,
        -15, 68.982,
        -14, 65.489,
        -13, 62.183,
        -12, 59.052,
        -11, 56.087,
        -10, 53.28,
        -9, 50.62,
        -8, 48.1,
        -7, 45.712,
        -6, 43.45,
        -5, 41.306,
        -4, 39.274,
        -3, 37.349,
        -2, 35.524,
        -1, 33.795,
        0, 32.116,
        1, 30.601,
        2, 29.128,
        3, 27.732,
        4, 26.408,
        5, 25.152,
        6, 23.962,
        7, 22.833,
        8, 21.762,
        9, 20.746,
        10, 19.783,
        11, 18.868,
        12, 18,
        13, 17.177,
        14, 16.395,
        15, 15.652,
        16, 14.947,
        17, 14.277,
        18, 13.641,
        19, 13.036,
        20, 12.461,
        21, 11.915,
        22, 11.395,
        23, 10.901,
        24, 10.431,
        25, 10,
        26, 9.557,
        27, 9.151,
        28, 8.765,
        29, 8.397,
        30, 8.047,
        31, 7.712,
        32, 7.394,
        33, 7.09,
        34, 6.8,
        35, 6.523,
        36, 6.259,
        37, 6.008,
        38, 5.767,
        39, 5.537,
        40, 5.318,
        41, 5.108,
        42, 4.907,
        43, 4.716,
        44, 4.532,
        45, 4.357,
        46, 4.189,
        47, 4.029,
        48, 3.875,
        49, 3.728,
        50, 3.588,
        51, 3.453,
        52, 3.324,
        53, 3.2,
        54, 3.081,
        55, 2.968,
        56, 2.859,
        57, 2.754,
        58, 2.654,
        59, 2.558,
        60, 2.466,
        61, 2.377,
        62, 2.293,
        63, 2.211,
        64, 2.133,
        65, 2.058,
        66, 1.986,
        67, 1.917,
        68, 1.85,
        69, 1.786,
        70, 1.725,
        71, 1.666,
        72, 1.61,
        73, 1.555,
        74, 1.503,
        75, 1.452,
        76, 1.404,
        77, 1.358,
        78, 1.313,
        79, 1.27,
        80, 1.228,
        81, 1.189,
        82, 1.15,
        83, 1.113,
        84, 1.078,
        85, 1.044,
        86, 1.011,
        87, 0.979,
        88, 0.948,
        89, 0.919,
        90, 0.89,
        91, 0.863,
        92, 0.837,
        93, 0.811,
        94, 0.787,
        95, 0.763,
        96, 0.74,
        97, 0.718,
        98, 0.697,
        99, 0.676,
        100, 0.657,
        101, 0.637,
        102, 0.619,
        103, 0.601,
        104, 0.584,
        105, 0.567,
        106, 0.551,
        107, 0.535,
        108, 0.52,
        109, 0.505,
        110, 0.491,
        111, 0.478,
        112, 0.464,
        113, 0.451,
        114, 0.439,
        115, 0.427,
        116, 0.415,
        117, 0.404,
        118, 0.393,
        119, 0.382,
        120, 0.371,
        121, 0.361,
        122, 0.351,
        123, 0.342,
        124, 0.333,
        125, 0.324,

        /* 结束行，用于搜索判断结束 */
        9999, 0};

/* 温度(摄氏度)，电阻(kΩ)，100K B25/50-3950K */
const float ntc_100K_B3950[] = {
        -40, 3402.936,
        -39, 3184.855,
        -38, 2982.102,
        -37, 2793.511,
        -36, 2618.010,
        -35, 2454.615,
        -34, 2302.423,
        -33, 2160.599,
        -32, 2028.380,
        -31, 1905.059,
        -30, 1789.987,
        -29, 1682.565,
        -28, 1582.242,
        -27, 1488.507,
        -26, 1400.8920,
        -25, 1318.9610,
        -24, 1242.3150,
        -23, 1170.5830,
        -22, 1103.4220,
        -21, 1040.5150,
        -20, 981.5699,
        -19, 926.3143,
        -18, 874.4971,
        -17, 825.8852,
        -16, 780.2627,
        -15, 737.4293,
        -14, 697.1992,
        -13, 659.3999,
        -12, 623.8711,
        -11, 590.4642,
        -10, 559.0409,
        -9, 529.4725,
        -8, 501.6397,
        -7, 475.4310,
        -6, 450.7430,
        -5, 427.4792,
        -4, 405.5499,
        -3, 384.8714,
        -2, 365.3656,
        -1, 346.9597,
        0, 329.5860,
        1, 313.1810,
        2, 297.6856,
        3, 282.7877,
        4, 268.8885,
        5, 255.7538,
        6, 243.3375,
        7, 231.5964,
        8, 220.4901,
        9, 209.9808,
        10, 200.0333,
        11, 190.6144,
        12, 181.6932,
        13, 173.2409,
        14, 165.2301,
        15, 157.6356,
        16, 150.4335,
        17, 143.6013,
        18, 137.1182,
        19, 130.9645,
        20, 125.1217,
        21, 119.5725,
        22, 114.3006,
        23, 109.2906,
        24, 104.5283,
        25, 100.0000,
        26, 95.6931,
        27, 91.5956,
        28, 87.6962,
        29, 83.9843,
        30, 80.4501,
        31, 77.0839,
        32, 73.8771,
        33, 70.8212,
        34, 67.9084,
        35, 65.1313,
        36, 62.4828,
        37, 59.9563,
        38, 57.5457,
        39, 55.2450,
        40, 53.0486,
        41, 50.9513,
        42, 48.9482,
        43, 47.0345,
        44, 45.2059,
        45, 43.4580,
        46, 41.8844,
        47, 40.2828,
        48, 38.7506,
        49, 37.2845,
        50, 35.8812,
        51, 34.5378,
        52, 33.2515,
        53, 32.0195,
        54, 30.8393,
        55, 29.7085,
        56, 28.6249,
        57, 27.5861,
        58, 26.5902,
        59, 25.6352,
        60, 24.7192,
        61, 23.8404,
        62, 22.9972,
        63, 22.1880,
        64, 21.4112,
        65, 20.6654,
        66, 19.9492,
        67, 19.2613,
        68, 18.6005,
        69, 17.9656,
        70, 17.3554,
        71, 16.7688,
        72, 16.2050,
        73, 15.6627,
        74, 15.1413,
        75, 14.6397,
        76, 14.1571,
        77, 13.6927,
        78, 13.2457,
        79, 12.8155,
        80, 12.4013,
        81, 12.0024,
        82, 11.6182,
        83, 11.2482,
        84, 10.8916,
        85, 10.5481,
        86, 10.2169,
        87, 9.8978,
        88, 9.5900,
        89, 9.3120,
        90, 9.0236,
        91, 8.7453,
        92, 8.4769,
        93, 8.2178,
        94, 7.9677,
        95, 7.7264,
        96, 7.4933,
        97, 7.2683,
        98, 7.0511,
        99, 6.8412,
        100, 6.6385,
        101, 6.4426,
        102, 6.2534,
        103, 6.0705,
        104, 5.8937,
        105, 5.7228,
        106, 5.5576,
        107, 5.3979,
        108, 5.2434,
        109, 5.0940,
        110, 4.9495,
        111, 4.8096,
        112, 4.6743,
        113, 4.5434,
        114, 4.4167,
        115, 4.2940,
        116, 4.1753,
        117, 4.0603,
        118, 3.9490,
        119, 3.8412,
        120, 3.7367,
        121, 3.6356,
        122, 3.5376,
        123, 3.4426,
        124, 3.3505,
        125, 3.2613,
        126, 3.1749,
        127, 3.0911,
        128, 3.0098,
        129, 2.9310,
        130, 2.8546,
        131, 2.7804,
        132, 2.7145,
        133, 2.6433,
        134, 2.5744,
        135, 2.5077,
        136, 2.4431,
        137, 2.3804,
        138, 2.3198,
        139, 2.2610,
        140, 2.2040,
        141, 2.1488,
        142, 2.0953,
        143, 2.0434,
        144, 1.9930,
        145, 1.9442,
        146, 1.8968,
        147, 1.8509,
        148, 1.8063,
        149, 1.7630,
        150, 1.7210,
        151, 1.6802,
        152, 1.6406,
        153, 1.6022,
        154, 1.5648,
        155, 1.5285,
        156, 1.4933,
        157, 1.4590,
        158, 1.4258,
        159, 1.3934,
        160, 1.3620,
        161, 1.3314,
        162, 1.3017,
        163, 1.2728,
        164, 1.2446,
        165, 1.2173,
        166, 1.1907,
        167, 1.1648,
        168, 1.1396,
        169, 1.1151,
        170, 1.0912,
        171, 1.0680,
        172, 1.0454,
        173, 1.0234,
        174, 1.0019,
        175, 0.9810,
        176, 0.9607,
        177, 0.9408,
        178, 0.9215,
        179, 0.9027,
        180, 0.8844,
        181, 0.8665,
        182, 0.8490,
        183, 0.8321,
        184, 0.8155,
        185, 0.7993,
        186, 0.7836,
        187, 0.7682,
        188, 0.7532,
        189, 0.7386,
        190, 0.7243,
        191, 0.7104,
        192, 0.6968,
        193, 0.6835,
        194, 0.6706,
        195, 0.6580,
        196, 0.6456,
        197, 0.6336,
        198, 0.6218,
        199, 0.6103,
        200, 0.5991,
        201, 0.5881,
        202, 0.5774,
        203, 0.5670,
        204, 0.5567,
        205, 0.5467,
        206, 0.5370,
        207, 0.5274,
        208, 0.5181,
        209, 0.5090,
        210, 0.5001,
        211, 0.4913,
        212, 0.4828,
        213, 0.4745,
        214, 0.4663,
        215, 0.4583,
        216, 0.4505,
        217, 0.4429,
        218, 0.4340,
        219, 0.4267,
        220, 0.4196,
        221, 0.4126,
        222, 0.4057,
        223, 0.3990,
        224, 0.3925,
        225, 0.3861,
        226, 0.3798,
        227, 0.3737,
        228, 0.3677,
        229, 0.3618,
        230, 0.3561,
        231, 0.3505,
        232, 0.3450,
        233, 0.3396,
        234, 0.3343,
        235, 0.3291,
        236, 0.3241,
        237, 0.3191,
        238, 0.3142,
        239, 0.3095,
        240, 0.3048,
        241, 0.3003,
        242, 0.2958,
        243, 0.2914,
        244, 0.2871,
        245, 0.2829,
        246, 0.2787,
        247, 0.2747,
        248, 0.2707,
        249, 0.2668,
        250, 0.2630,
        251, 0.2593,
        252, 0.2556,
        253, 0.2520,
        254, 0.2484,
        255, 0.2450,
        256, 0.2416,
        257, 0.2382,
        258, 0.2350,
        259, 0.2318,
        260, 0.2286,
        261, 0.2234,
        262, 0.2204,
        263, 0.2175,
        264, 0.2147,
        265, 0.2119,
        266, 0.2092,
        267, 0.2065,
        268, 0.2039,
        269, 0.2013,
        270, 0.1988,
        271, 0.1963,
        272, 0.1939,
        273, 0.1915,
        274, 0.1892,
        275, 0.1869,
        276, 0.1846,
        277, 0.1824,
        278, 0.1802,
        279, 0.178,
        280, 0.1759,
        281, 0.1739,
        282, 0.1718,
        283, 0.1698,
        284, 0.1679,
        285, 0.1659,
        286, 0.164,
        287, 0.1622,
        288, 0.1603,
        289, 0.1585,
        290, 0.1568,
        291, 0.155,
        292, 0.1533,
        293, 0.1516,
        294, 0.15,
        295, 0.1484,
        296, 0.1468,
        297, 0.1452,
        298, 0.1436,
        299, 0.1421,
        300, 0.1406,

        /* 结束行，用于搜索判断结束 */
        9999, 0};

/* 温度(摄氏度)，电阻(kΩ)，200K B25/50-4260K */
const float ntc_200K_B4260[] = {
        -20, 2106.124,
        -19, 1985.095,
        -18, 1871.640,
        -17, 1765.247,
        -16, 1665.445,
        -15, 1571.793,
        -14, 1483.884,
        -13, 1401.339,
        -12, 1323.804,
        -11, 1250.952,
        -10, 1182.478,
        -9, 1118.098,
        -8, 1057.550,
        -7, 1000.585,
        -6, 946.9761,
        -5, 896.5093,
        -4, 848.9858,
        -3, 804.2202,
        -2, 762.0396,
        -1, 722.2826,
        0, 684.7987,
        1, 649.4474,
        2, 616.0975,
        3, 586.0635,
        4, 556.7038,
        5, 528.9471,
        6, 502.6992,
        7, 477.8718,
        8, 454.3821,
        9, 432.1526,
        10, 411.1105,
        11, 391.1874,
        12, 372.3191,
        13, 354.4455,
        14, 337.5101,
        15, 321.4597,
        16, 306.2444,
        17, 291.8173,
        18, 278.1343,
        19, 265.1540,
        20, 252.8375,
        21, 241.1480,
        22, 230.0510,
        23, 219.5141,
        24, 209.5067,
        25, 200.0000,
        26, 190.9669,
        27, 182.3819,
        28, 174.2209,
        29, 166.4613,
        30, 159.0815,
        31, 152.0616,
        32, 145.3825,
        33, 139.0263,
        34, 132.9759,
        35, 127.2155,
        36, 121.7300,
        37, 116.5052,
        38, 111.5276,
        39, 106.7844,
        40, 102.2638,
        41, 97.9543,
        42, 93.8453,
        43, 89.9266,
        44, 86.1886,
        45, 82.6223,
        46, 78.3041,
        47, 75.0664,
        48, 71.9776,
        49, 69.0302,
        50, 66.2172,
        51, 63.5317,
        52, 60.9676,
        53, 58.5188,
        54, 56.1795,
        55, 53.9446,
        56, 51.8087,
        57, 49.7672,
        58, 47.8155,
        59, 45.9492,
        60, 44.1642,
        61, 42.4567,
        62, 40.8229,
        63, 39.2594,
        64, 37.7629,
        65, 36.3301,
        66, 34.9582,
        67, 33.6442,
        68, 32.3855,
        69, 31.1796,
        70, 30.0239,
        71, 28.9163,
        72, 27.8544,
        73, 26.8362,
        74, 25.8598,
        75, 24.9233,
        76, 24.0248,
        77, 23.1627,
        78, 22.3353,
        79, 21.5411,
        80, 20.7786,
        81, 20.0465,
        82, 19.3433,
        83, 18.6679,
        84, 18.0191,
        85, 17.3956,
        86, 16.7964,
        87, 16.2204,
        88, 15.6667,
        89, 15.3971,
        90, 14.8786,
        91, 14.3796,
        92, 13.8994,
        93, 13.4371,
        94, 12.9921,
        95, 12.5635,
        96, 12.1509,
        97, 11.7534,
        98, 11.3705,
        99, 11.0016,
        100, 10.6462,
        101, 10.3036,
        102, 9.9735,
        103, 9.6552,
        104, 9.3483,
        105, 9.0524,
        106, 8.7670,
        107, 8.4918,
        108, 8.2262,
        109, 7.9701,
        110, 7.7229,
        111, 7.4843,
        112, 7.2540,
        113, 7.0317,
        114, 6.8171,
        115, 6.6099,
        116, 6.4098,
        117, 6.2165,
        118, 6.0298,
        119, 5.8495,
        120, 5.6752,
        121, 5.5068,
        122, 5.3440,
        123, 5.1867,
        124, 5.0346,
        125, 4.8875,
        126, 4.7453,
        127, 4.6078,
        128, 4.4748,
        129, 4.3462,
        130, 4.2217,
        131, 4.1013,
        132, 3.9653,
        133, 3.8526,
        134, 3.7437,
        135, 3.6385,
        136, 3.5368,
        137, 3.4385,
        138, 3.3434,
        139, 3.2515,
        140, 3.1626,
        141, 3.0767,
        142, 2.9935,
        143, 2.9130,
        144, 2.8351,
        145, 2.7597,
        146, 2.6867,
        147, 2.6160,
        148, 2.5476,
        149, 2.4813,
        150, 2.4170,
        151, 2.3548,
        152, 2.2945,
        153, 2.2361,
        154, 2.1794,
        155, 2.1245,
        156, 2.0713,
        157, 2.0196,
        158, 1.9695,
        159, 1.9209,
        160, 1.8738,
        161, 1.8281,
        162, 1.7837,
        163, 1.7406,
        164, 1.6988,
        165, 1.6581,
        166, 1.6187,
        167, 1.5804,
        168, 1.5432,
        169, 1.5071,
        170, 1.4720,
        171, 1.4378,
        172, 1.4047,
        173, 1.3725,
        174, 1.3411,
        175, 1.2906,
        176, 1.2603,
        177, 1.2308,
        178, 1.2021,
        179, 1.1742,
        180, 1.1471,
        181, 1.1207,
        182, 1.0950,
        183, 1.0699,
        184, 1.0456,
        185, 1.0219,
        186, 0.9988,
        187, 0.9764,
        188, 0.9545,
        189, 0.9332,
        190, 0.9124,
        191, 0.8922,
        192, 0.8726,
        193, 0.8534,
        194, 0.8347,
        195, 0.8165,
        196, 0.7988,
        197, 0.7815,
        198, 0.7647,
        199, 0.7483,
        200, 0.7322,
        201, 0.7166,
        202, 0.7014,
        203, 0.6866,
        204, 0.6721,
        205, 0.6580,
        206, 0.6443,
        207, 0.6309,
        208, 0.6178,
        209, 0.6050,
        210, 0.5926,
        211, 0.5804,
        212, 0.5685,
        213, 0.5570,
        214, 0.5457,
        215, 0.5346,
        216, 0.5239,
        217, 0.5134,
        218, 0.5031,
        219, 0.4931,
        220, 0.4833,
        221, 0.4738,
        222, 0.4644,
        223, 0.4553,
        224, 0.4464,
        225, 0.4377,
        226, 0.4292,
        227, 0.4209,
        228, 0.4127,
        229, 0.4048,
        230, 0.3970,
        231, 0.3895,
        232, 0.3821,
        233, 0.3748,
        234, 0.3678,
        235, 0.3609,
        236, 0.3541,
        237, 0.3475,
        238, 0.3410,
        239, 0.3347,
        240, 0.3285,
        241, 0.3225,
        242, 0.3166,
        243, 0.3108,
        244, 0.3052,
        245, 0.2996,
        246, 0.2942,
        247, 0.2889,
        248, 0.2837,
        249, 0.2787,
        250, 0.2737,
        251, 0.2688,
        252, 0.2641,
        253, 0.2594,
        254, 0.2549,
        255, 0.2504,
        274, 0.1811,
        275, 0.1781,
        276, 0.1752,
        277, 0.1724,
        278, 0.1696,
        279, 0.1668,
        280, 0.1642,
        281, 0.1615,
        282, 0.1589,
        283, 0.1564,
        284, 0.1539,
        285, 0.1515,
        286, 0.1491,
        287, 0.1468,
        288, 0.1445,
        289, 0.1422,
        290, 0.1400,
        291, 0.1378,
        292, 0.1357,
        293, 0.1336,
        294, 0.1316,
        295, 0.1295,
        296, 0.1276,
        297, 0.1256,
        298, 0.1237,
        299, 0.1219,
        300, 0.1200,

        /* 结束行，用于搜索判断结束 */
        9999, 0};

#define NTC_TYPE_NUM 2
const float *ntc_table[NTC_TYPE_NUM] = {
        ntc_10K_B3950,
        ntc_100K_B3950};

/*
*********************************************************************************************************
*    函 数 名: CalculNtcTemper
*    功能说明: 根据电阻值计算NTC温度值
*    形    参: _res : 电阻值，KΩ
*    返 回 值: 温度值
*   优 先 级: 无
*********************************************************************************************************
*/
float CalculNtcTemperFloat(float _res)
{
    uint16_t i;
    float x1, y1, x2, y2;
    uint16_t idx;
    const float *pTable;
    float temper;

    if (g_tParam.NtcType >= NTC_TYPE_NUM)
    {
        g_tParam.NtcType = 0;
    }
    pTable = ntc_table[g_tParam.NtcType];

    idx = 0;

    /* 搜索当前电阻对应的温度 */
    for (i = 0; i < 500; i++)
    {
        if (_res > pTable[2 * i + 1])
        {
            if (i > 0)
            {
                idx = i - 1;
            }
            else
            {
                idx = 0;
            }
            break;
        }
        if (pTable[2 * i + 0] == 9999)
        {
            idx = i - 2;
            break;
        }
    }

    x1 = pTable[2 * idx + 1];                /* 电阻 */
    y1 = pTable[2 * idx + 0];                /* 温度 */
    x2 = pTable[2 * (idx + 1) + 1]; /* 电阻 */
    y2 = pTable[2 * (idx + 1) + 0]; /* 温度 */

    temper = CaculTwoPointFloat(x1, y1, x2, y2, _res);

    return temper;
}

/*
*********************************************************************************************************
*    函 数 名: CalculNtcRes
*    功能说明: 计算NTC电阻值
*    形    参: ref_res : 上拉参考电阻， _adc : 当前ADC值  
*    返 回 值: 电阻值. K欧
* 
*********************************************************************************************************
*/
float CalculNtcRes(float _adc)
{
    /* 
        大于20欧按 参考电阻比值计算
        小于20欧按第1点和第2点进行线性计算，简单处理。    
    
        这个方案不太好，后面需要找更好的修正算法。
        问题在第2个点附近，阻值会调动3左右.
    */
    float X;
    float ref_res3;
    //    float ref_res2;

    /* 根据 (x2,y2) 校准点和 (x3,y3) 校准点，修正曲线 */

    if (_adc < g_tCalib.NtcRes.x2 + 5)
    {
        X = CaculTwoPointFloat(g_tCalib.NtcRes.x1, g_tCalib.NtcRes.y1, g_tCalib.NtcRes.x2, g_tCalib.NtcRes.y2, _adc);

        /* 0 ->0  9 -> 10  20->20 临时处理 */
        if (X < 9)
        {
            X = CaculTwoPointFloat(0, 0, 9, 10, X);
        }
        else
        {
            X = CaculTwoPointFloat(9, 10, 20, 20, X);
        }
    }
    else
    {
        ref_res3 = CalculRefRes(g_tCalib.NtcRes.x3, g_tCalib.NtcRes.y3); /* 计算内部上拉电阻 */
        /*
        公式  X/(R+X) = ADC/65535
        
        X = ADC * R /(65535 - ADC);
        */

        X = _adc * ref_res3 / (65535 - _adc);
    }

    if (X < 0)
    {
        X = 0;
    }

    return X;
}

/*
*********************************************************************************************************
*    函 数 名: CalculRefRes
*    功能说明: 计算内部电路参考电阻
*    形    参: _adc : 当前ADC值, _res : 标定电阻，K欧
*    返 回 值: 电阻值. K欧
* 
*********************************************************************************************************
*/
float CalculRefRes(float _adc, float _res)
{
    /* 参考电阻比值方案 */
    float X;

    /*
    公式  Rx / (Rf + Rx) = ADC/65535
    
        Rx = ADC * Rf /(65535 - ADC);
        Rf = Rx /(ADC/(65535 - ADC));
    */

    X = _res / (_adc / (65535 - _adc));

    return X;
}

/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/
